package com.shell.customer.accreditation.rx;

import com.shell.customer.accreditation.AccreditEvent;
import com.shell.customer.accreditation.vo.AccreditationVo;
import com.shell.customer.base.service.CusRelService;
import com.shell.customer.base.service.CusTagRecService;
import com.shell.customer.invitation.service.InvtCusService;
import com.shell.customer.po.CusInvt;
import com.shell.customer.po.CusRec;
import com.shell.framework.rx.OnErrorNotImplementedSubscriber;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class SetCusRelAndTagAfterAccreditSubscriber extends OnErrorNotImplementedSubscriber<AccreditEvent> {
	@Autowired
	private InvtCusService invtCusService;
	@Autowired
	private CusTagRecService cusTagRecService;
	@Autowired
	private CusRelService cusRelService;

	public void onApplicationEvent(AccreditEvent event) {
		AccreditationVo accreditationVo = event.getAccreditationVo();
		CusRec cus = accreditationVo.getCustomerC();
		CusInvt cusInvt = new CusInvt();
		cusInvt.setInviteeId(cus.getCusId());
		List<CusInvt> invts = this.invtCusService.selectByEntity(cusInvt);
		for (CusInvt invt : invts) {
			this.cusRelService.setCusRel(invt, cus);
			this.cusTagRecService.addTagByInvt(invt);
		}
	}
}
